package com.example.litterpainterdemo.welcome


import android.content.Context
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.navigation.fragment.findNavController
import com.example.litterpainterdemo.R

import com.example.litterpainterdemo.databinding.FragmentWelcomeBinding
import com.example.litterpainterdemo.utils.AnimUtils
import com.example.litterpainterdemo.utils.Constants
import com.example.litterpainterdemo.utils.SPUtils


class WelcomeFragment : Fragment() {
    private lateinit var binding:FragmentWelcomeBinding


    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding = FragmentWelcomeBinding.inflate(inflater,container,false)
        return binding.root
    }

    override fun onStart() {
        super.onStart()
        AnimUtils.addScaleAndAlphaAnim(
            binding.logo,
            onEnd = {
                navigate()
            }
        )

    }

    //切换fragment
    private fun navigate(){
        //判断是否第一次使用app
        if(SPUtils.getInstance(requireContext()).isFirst){
            findNavController().navigate(R.id.action_welcomeFragment_to_guideFragment)
        }else{
            findNavController().navigate(R.id.action_welcomeFragment_to_homeFragment)
        }

    }

}